﻿using System;
//using System.Collections.Generic;
//using System.Linq;
//using System.Net;
using System.Windows;
using System.Windows.Controls;
//using System.Windows.Documents;
//using System.Windows.Input;
//using System.Windows.Media;
//using System.Windows.Media.Animation;
//using System.Windows.Shapes;

namespace Uhul.Controls
{


  /// <summary>
  /// AutocompleteBox with watermark under text input area
  /// </summary>
  [TemplateVisualState(Name = "WatermarkOff", GroupName = "WatermarkStates")]
  [TemplateVisualState(Name = "WatermarkOn", GroupName = "WatermarkStates")]
  public class WatermarkAutoCompleteBox : AutoCompleteBox
  {
    public WatermarkAutoCompleteBox()
    {
      this.DefaultStyleKey = typeof(WatermarkAutoCompleteBox);
      this.TextChanged += OnTextChanged;
      this.LostFocus += OnLostFocus;
      this.GotFocus += OnGotFocus;

      //this.Populating =+

    }




    /// <summary>
    /// WatermarkText dependency property
    /// </summary>
    public static readonly DependencyProperty WatermarkTextProperty = DependencyProperty.Register(
        "WatermarkText", typeof(string), typeof(WatermarkAutoCompleteBox), new PropertyMetadata(OnWatermarkTextPropertyChanged));

    /// <summary>
    /// Gets or sets a value indicating Watermark text displayed under Text input.  This is a dependency property.
    /// </summary>
    /// <value></value>
    /// <returns></returns>
    public string WatermarkText
    {
      get { return (string)GetValue(WatermarkTextProperty); }
      set { SetValue(WatermarkTextProperty, value); }
    }





    private void OnTextChanged(object sender, RoutedEventArgs e)
    {
      if (this.MinimumPrefixLength <= this.Text.Length)
        VisualStateManager.GoToState(this, "WatermarkOff", true);
      else
        VisualStateManager.GoToState(this, "WatermarkOn", true);

    }




    private void OnGotFocus(object sender, RoutedEventArgs e)
    {
        VisualStateManager.GoToState(this, "WatermarkOff", true);
    }




    private void OnLostFocus(object sender, RoutedEventArgs e)
    {
      if (this.MinimumPrefixLength <= this.Text.Length)
        VisualStateManager.GoToState(this, "WatermarkOff", true);
      else
        VisualStateManager.GoToState(this, "WatermarkOn", true);
    }






    private static void OnWatermarkTextPropertyChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args)
    { 
      
    }



  }

}
